package cn.good.yan.controller;

import cn.good.yan.pojo.CommonResult;
import cn.good.yan.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * 库存服务
 *
 * @author shengren.yan
 * @create 2024-02-22
 */
@RestController
@Slf4j
public class StorageController {

    @Autowired
    StorageService storageService;

    // 扣除 该产品 的仓库的库存
    @PostMapping("/storage/decrease")
    @ResponseBody
    public CommonResult decrease(@RequestParam("productId") Long productId, @RequestParam("count") Integer count) {

        // AT、XA 模式 - 减库存
//        storageService.decrease(productId, count);

        // tcc 模式 - 减库存
        storageService.changeStockTcc(productId, count);

        return new CommonResult(200, "扣减库存成功！");
    }

}
